<?php require "../global.php";
 require "Uifunction.php";
?>
<script type="text/javascript" src="http://lib.sinaapp.com/js/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript" src="/Public/jsLibrary/Jslibary.js"></script>
<style>
body,td{font-size:12px;}
.spanplace{display:none;}
.xztdbgc{background-color:#FFDD99;}
body {
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
}
</style>

<?php
$thismonth=$_REQUEST["thismonth"];//本月值
if($thismonth=="") $thismonth=date("Y-m");
$thefirstdayofweek=date('w',strtotime($thismonth."-01"));//本月第一天是星期几

//如果这个月的第一天不是星期一,那么，它的前面就以上一个月的补齐
//获取前上一个月的日期,以这个月的第一天为基准
function getqiandate($datestr,$num){
	return date("Y-m-d",strtotime($datestr)-$num*3600*24);
}

//获取前一个月的日期，返回值是2012-09
function getqimonth($thismonth){
	$yearn=preg_replace("/\-[\d]{1,2}$/","",$thismonth);
	$month=preg_replace("/^[\d]{4}\-[0]*/","",$thismonth);
	
	$nowmonth=($month==1)?12:$month-1;
	if($month==1){
		$nowmonth=12;
		$yearn=$yearn-1;
	}
	else{
		$nowmonth=$month-1;
	}
	return $yearn."-".substr("0".$nowmonth,-2);
}

//获取后一个月的日期
function getnextmonth($thismonth){
	$yearn=preg_replace("/\-[\d]{1,2}$/","",$thismonth);
	$month=preg_replace("/^[\d]{4}\-[0]*/","",$thismonth);
	if($month==12){
		$month=1;
		$yearn+=1;
	}
	else{
		$month+=1;
	}
	return $yearn."-".substr("0".$month,-2);
	
}

$qianbunum=$thefirstdayofweek==0?6:$thefirstdayofweek-1;//前面要补的天数
$monthmaxnum=date("t",strtotime($thismonth."-01"));//这个月有多少天

$lastbunum=7-($monthmaxnum+$qianbunum) % 7;
$lastbunum=$lastbunum==7?0:$lastbunum;//获取后面需要被的天数


//计算这次要循环的次数
$maxfornum=$qianbunum+$lastbunum+$monthmaxnum;

//获取本次的开始天数
$stardate= getqiandate($thismonth,$qianbunum);


?>
<div>
  <div style="float:left; width:200px; background-color:#FFF">
<table width="200" border="1" cellspacing="0" cellpadding="0" bordercolor="#ccc" style="border-collapse:collapse">
  <tr>
    <td height="37" colspan="7" align="center"><table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td width="31%" height="27"><a href="?MenuId=<? echo $MenuId;?>&fieldid=<? echo $fieldid;?>&hid=<? echo $hid;?>&tid=<? echo $tid;?>&thismonth=<?php $pmonth= getqimonth($thismonth);echo $pmonth; ?>"><?php echo preg_replace("/^[\d]{4}\-[0]*/","",$pmonth);?>月</a></td>
        <td width="39%"><strong><?php echo str_replace("-","年",$thismonth)."月";?></strong><span class="spanplace" id="placeall">全选<input type="checkbox" id="cpall"></span></td>
        <td width="30%" align="right"><a href="?MenuId=<? echo $MenuId;?>&fieldid=<? echo $fieldid;?>&hid=<? echo $hid;?>&tid=<? echo $tid;?>&thismonth=<?php $nmonth= getnextmonth($thismonth);echo $nmonth;?>"><?php echo preg_replace("/^[\d]{4}\-[0]*/","",$nmonth);?>月</a></td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <td width="11%" height="25" align="center">一<span class="spanplace" id="place1"><input type="checkbox" id="cpz1"></span></td>
    <td width="11%" align="center">二<span class="spanplace" id="place2"><input type="checkbox" id="cpz2"></span></td>
    <td width="11%" align="center">三<span class="spanplace" id="place3"><input type="checkbox" id="cpz3"></span></td>
    <td width="11%" align="center">四<span class="spanplace" id="place4"><input type="checkbox" id="cpz4"></span></td>
    <td width="11%"  align="center">五<span class="spanplace" id="place5"><input type="checkbox" id="cpz5"></span></td>
    <td width="11%" align="center">六<span class="spanplace" id="place6"><input type="checkbox" id="cpz6"></span></td>
    <td width="11%" align="center">日<span class="spanplace" id="place0"><input type="checkbox" id="cpz0"></span></td>
  </tr>
 <?php
 $zcthismonth=turntostrtozc($thismonth);
 preg_match_all("/".$zcthismonth."\-[\d]{1,2}\|[\d\.]+\|[\d\.]+\|[\d]*\|[\d]+/",$datecontent,$datecontentarr);//只获取本月的日期值
 $dcontentarr=array();//存放本月分解的数值

 
for($i=1;$i<=$maxfornum;$i++){
	$thisv=date("Y-m-d",strtotime($stardate)+($i-1)*3600*24);
 if($i %7 ==1){
?>  <tr><?php }?>
    <td width="11%" align="center"   height="25"  
    <?php if(strstr($thisv,$thismonth)=="" or date("Y-m")>$thismonth or strtotime(date("Y-m-d")) > strtotime($thisv)    ){
		echo "style='background-color:#ccc;cursor:pointer;' ";}
		else{
			echo "data='".$thisv."' week='".date("w",strtotime($thisv))."' style='cursor:pointer;'";
		}
		?>
        class="">
		<?php echo preg_replace("/^[\d]{4}\-[\d]{1,2}\-[0]*/","",$thisv);?>
       
    </td>
 <?php if($i % 7==0){?> </tr><?php }?>
 <?php
}
 ?> 
</table>

</div>
</div>

<script language="javascript">
$(document).ready(function(){
	$("td[data^='20']").bind("click",function(){
		v=$(this).attr("data");
		parent.let_Val("<?php echo $_REQUEST["domid"]?>",v);
	});
	
});
</script>